home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / ingres04.lzh / source / gutil / bitpos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1985-01-23  |  454 b   |  32 lines

  1. # include    <sccs.h>
  2.  
  3. SCCSID(@(#)bitpos.c    8.1    12/31/84)
  4.  
  5. /*
  6. **  FIND HIGH ORDER BIT POSITION
  7. **
  8. **    The position of the highest ordered one bit in `wd' is
  9. **    found and returned.  Bits are numbered 0 -> 15, from
  10. **    right (low-order) to left (high-order) in word.
  11. */
  12.  
  13. bitpos(wd)
  14. register int    wd;
  15. {
  16.     register int    i, j;
  17.     register int    pos;
  18.  
  19.     pos = -1;
  20.  
  21.     for (i = 1, j = 0; wd; i <<= 1, j++)
  22.     {
  23.         if (wd & i)
  24.         {
  25.             pos = j;
  26.             wd &= ~i;
  27.         }
  28.     }
  29.  
  30.     return (pos);
  31. }
  32.